/*
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};
*/
class Solution {
public:
    vector<vector<int> > Print(TreeNode* pRoot) {
        queue<TreeNode*> q;
        vector<vector<int>> vv;
        if (pRoot == nullptr)
            return vv;
        q.push(pRoot);
        int len = q.size();
        int flag = 1;
        while (!q.empty())
        {
            vector<int> v;
            len = q.size();
            for (int i = 0; i < len; i++)
            {
                TreeNode* tmp = q.front();
                q.pop();
                v.push_back(tmp->val);
                if (tmp->left)
                    q.push(tmp->left);
                if (tmp->right)
                    q.push(tmp->right);
            }
            if (flag % 2 == 0)
                reverse(v.begin(), v.end());
            flag++;
            vv.push_back(v);
        }
        return vv;
    }

};